package com.example.mcpclient.service;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.model.ChatResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.util.stream.Collectors;

/**
 * 意图服务类, 识别用户意图
 *
 * @author xuguang
 */
@Service
public class IntendService {


    @Autowired
    private ChatClient chatClient;

    @Value("classpath:/prompts/intent.st")
    private org.springframework.core.io.Resource intentTemplate;


    /**
     * ai返回的原始信息
     */
    public Flux<ChatResponse> guessIntentWithOriginal(String msg) {
        return chatClient.prompt(msg)
                .system(intentTemplate)
                .stream()
                .chatResponse();
    }


    /**
     * 通过msg返回意图识别的枚举
     */
    public Mono<String> guessIntent(String msg) {
        return chatClient.prompt(msg)
                .system(intentTemplate)
                .stream()
                .content()
                .collect(Collectors.joining());
    }


}
